#include "Quest.h"
#include "GFuns.h"
#include "Game.h"

class QuestGodsTears : public Quest
{
	public:
		QuestGodsTears();
		virtual ~QuestGodsTears(){};

		virtual Phrase* GetPhrase(Character* aCharacter);
		virtual void OnAction(EMenuAction aAction,
			ActionData aArg1 = ActionData(), ActionData aArg2 = ActionData(), ActionData aArg3 = ActionData()){};

	private:
		int gold;
		Item godsTears;
};

QuestGodsTears::QuestGodsTears() :
	godsTears(ITEM_QUEST, QUEST_GODS_TEARS),
	gold(rand()%100+50)
{
}

Phrase* QuestGodsTears::GetPhrase(Character* aCharacter)
{
	string sentence;
	Character* hero = Game::GetHero();

	if(progress == QUEST_STATUS_NEW)
	{
		sentence = "Hello ";
		sentence += (hero->IsMale() ? "boy" : "girl");
		sentence += "! You must be ";
		sentence += hero->GetName();
		sentence += "!";

		Phrase* Aa = Phrase::CreatePhrase(sentence);
		Phrase* A = Phrase::CreatePhrase("Stay a while, and listen...");
		Phrase* Ba = Phrase::CreatePhrase("Our Gods are sad and every morning");
		Phrase* Bb = Phrase::CreatePhrase("they cry over the dead.");
		Phrase* Bc = Phrase::CreatePhrase("Find their tears and bring me some.");
		Phrase* Bd = Phrase::CreatePhrase("Make sure to put them in");
		Phrase* Be = Phrase::CreatePhrase("an empty flask.");
		Phrase* B = Phrase::CreatePhrase("Do you accept this quest?");
		Phrase* C = Phrase::CreatePhrase("I'll wait for your return.");
		Phrase* D = Phrase::CreatePhrase("I suspect she was a decent person.");
		Phrase* E = Phrase::CreatePhrase("So be it. Be well, " + hero->GetName() + ".");

		phrase = Aa;
		Aa->nextPhrase = A;
		A->AddOption("Yes?",Ba);
		A->AddOption("Maybe later",E);
		Ba->nextPhrase = Bb;
		Bb->nextPhrase = Bc;
		Bc->nextPhrase = Bd;
		Bd->nextPhrase = Be;
		Be->nextPhrase = B;
		B->AddOption("I will help you if you'll pay me.",C);
		B->AddOption("Yes, of course.",C);
		B->AddOption("You remind me my grandma.",D);
		B->AddOption("I need to think about it.",E);
		D->nextPhrase = B;
		C->SetNextQuestStatus(QUEST_STATUS_TAKEN,this);
	}
	else if(progress == QUEST_STATUS_TAKEN && !hero->HaveItem(&godsTears))
	{
		Phrase* A = Phrase::CreatePhrase("I'm disappointed. You need to try harder.");
		Phrase* B = Phrase::CreatePhrase("I'll wait for your return.");
		Phrase* C = Phrase::CreatePhrase("So be it. Be well, " + hero->GetName() + ".");

		phrase = A;
		A->AddOption("I'll try again",B);
		A->AddOption("I've change my mind. Do it yourself.",C);
		C->SetNextQuestStatus(QUEST_STATUS_NEW,this);
	}
	else if(progress == QUEST_STATUS_TAKEN && hero->HaveItem(&godsTears))
	{
		Phrase* A = Phrase::CreatePhrase("I'm glad you came back with the tears.");
		Phrase* B = Phrase::CreatePhrase("Here is your reward - " + iToString(gold) + "G. Be well "+hero->GetName() + ".");

		phrase = A;
		A->AddOption("Stop talking. Give me my money!",B);
		A->AddOption("I'm glad I could help.",B);
		B->SetNextQuestStatus(QUEST_STATUS_DONE,this);

		hero->SetGold(hero->GetGold() + gold);
		hero->GetInventory()->RemoveItem(&godsTears);
	}

	return phrase;
}

Quest* GetQuestGodsTears()
{
	return new QuestGodsTears();
}